//定义JS的模块控制器
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'business/source/index',
                    add_url: 'business/source/add',
                    edit_url: 'business/source/edit',
                    del_url: 'business/source/del',
                    table: 'business_source',
                }
            });

            //页面中的渲染元素
            var table = $("#table")

            //渲染表格并发送请求
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url, //请求的地址
                pk: 'id',  //主建字段
                sortName: 'id', //排序字段
                columns: [ //这个表中显示的字段
                    { checkbox: true },
                    { field: 'id', title: 'ID', sortable: true, operate: false },
                    { field: 'name', title: __('name'), operate: 'LIKE' },
                    {
                        field: 'operate',
                        title: __('Operate'),
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate
                    }
                ]
            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    }


    //返回值
    return Controller;
});